#ifndef     __ERROR_H
#define     __ERROR_H

#include <stdint.h>

namespace utils {

namespace ec {

constexpr uint8_t OK = 0x00;
constexpr uint8_t FLASH_ERR = 0x01;
constexpr uint8_t PARSE_ERR = 0x02;
constexpr uint8_t INVALID = 0x03;
constexpr uint8_t OTA_ID_INVALID = 0x04;
constexpr uint8_t OTA_MD5_INVALID = 0x05;
constexpr uint8_t STORE_SUM_FAIL = 0x06;

}

struct Error {

    Error() : err_code(ec::OK) {}
    Error(uint8_t v) : err_code(v) {}

    inline operator bool() const {
        return err_code != ec::OK;
    }

    inline Error& operator=(uint8_t value) {
        err_code = value;
        return *this;
    }

    inline bool is_ok() const {
        return err_code == ec::OK;
    }

    Error& operator=(int) = delete;

    uint8_t err_code;
};

}


#endif
